package cn.com.blueInfo.bpm.person.controller;

import cn.com.blueInfo.bpm.common.controller.BaseController;
import cn.com.blueInfo.bpm.common.validation.Create;
import cn.com.blueInfo.bpm.common.validation.Update;
import cn.com.blueInfo.bpm.common.validation.UpdatePartial;
import cn.com.blueInfo.bpm.person.request.PostDefDTO;
import cn.com.blueInfo.bpm.person.response.PostDefVO;
import cn.com.blueInfo.bpm.person.service.PostDefService;
import cn.com.blueInfo.utils.result.ResultInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.groups.Default;
import java.util.List;

/**
 * 岗位定义表 前端控制器
 * @author suxch
 * @since 2025-08-24 01:39:52
 */
@Tag(name = "岗位定义 接口")
@RestController
@RequestMapping("/person/postDef")
public class PostDefController extends BaseController {

    @Autowired
    private PostDefService postDefService;

    /**
     * 新建岗位定义
     * @param postDefDTO 岗位定义参数
     * @return ResultInfo
     */
    @Operation(summary = "新增岗位定义")
    @PostMapping("/addInfo")
    public ResultInfo<Integer> createPostDef(
            @Validated({Create.class, Default.class}) @RequestBody PostDefDTO postDefDTO) {
        return postDefService.addPostDef(postDefDTO);
    }

    /**
     * 批量新建岗位定义
     * @param postDefDTOList 岗位定义参数列表
     * @return ResultInfo
     */
    @Operation(summary = "批量新建岗位定义")
    @PostMapping("/addInfoList")
    public ResultInfo<Integer> batchCreatePostDef(
            @Validated({Create.class, Default.class}) @RequestBody List<PostDefDTO> postDefDTOList) {
        return postDefService.batchAddPostDef(postDefDTOList);
    }

    /**
     * 根据ID删除岗位定义
     * @param postDefId 岗位定义ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除岗位定义")
    @DeleteMapping("/removeInfo/{postDefId}")
    public ResultInfo<Integer> deletePostDefById(
            @Parameter(name = "ID") @PathVariable Long postDefId) {
        return postDefService.removePostDef(postDefId);
    }

    /**
     * 批量根据ID删除岗位定义
     * @param postDefIdList 岗位定义ID列表
     * @return ResultInfo
     */
    @Operation(summary = "根据ID删除岗位定义")
    @DeleteMapping("/removeInfoList/{postDefIdList}")
    public ResultInfo<Integer> batchDeletePostDefById(
            @Parameter(name = "ID") @PathVariable List<Long> postDefIdList) {
        return postDefService.batchRemovePostDef(postDefIdList);
    }

    /**
     * 根据ID全量更新岗位定义
     * @param postDefId 岗位定义ID
     * @param postDefDTO 岗位定义参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID全量更新岗位定义")
    @PutMapping("/modifyInfo/{postDefId}")
    public ResultInfo<Integer> updatePostDefFull(
            @Parameter(name = "ID") @PathVariable Long postDefId,
            @Validated({Update.class, Default.class}) @RequestBody PostDefDTO postDefDTO) {
        validateUpdateId(postDefId, postDefDTO.getId());
        return postDefService.modifyPostDef(postDefDTO);
    }

    /**
     * 根据ID部分更新岗位定义
     * @param postDefId 岗位定义ID
     * @param postDefUpdatePartialDTO 岗位定义参数
     * @return ResultInfo
     */
    @Operation(summary = "根据ID部分更新岗位定义")
    @PatchMapping("/modifyPartialInfo/{postDefId}")
    public ResultInfo<Integer> updatePostDefPartial(
            @Parameter(name = "ID") @PathVariable Long postDefId,
            @Validated({UpdatePartial.class, Default.class}) @RequestBody
            PostDefDTO.UpdatePartialDTO postDefUpdatePartialDTO) {
        validateUpdateId(postDefId, postDefUpdatePartialDTO.getId());
        return postDefService.modifyPostDefPartial(postDefUpdatePartialDTO);
    }

    /**
     * 根据ID查询岗位定义
     * @param postDefId 岗位定义ID
     * @return ResultInfo
     */
    @Operation(summary = "根据ID查询岗位定义")
    @GetMapping("/getInfo/{postDefId}")
    public ResultInfo<PostDefVO> getPostDefById(
            @Parameter(name = "ID") @PathVariable Long postDefId) {
        return postDefService.queryPostDefById(postDefId);
    }

    /**
     * 分页查询岗位定义
     * @param postDefQueryDTO 岗位定义参数
     * @return ResultInfo
     */
    @Operation(summary = "分页查询岗位定义")
    @GetMapping("/getInfos")
    public ResultInfo<Page<PostDefVO>> getPostDefPage(
            @Validated PostDefDTO.QueryDTO postDefQueryDTO) {
        return postDefService.queryPostDefPage(postDefQueryDTO);
    }

    /**
     * 根据条件查询岗位定义
     * @param postDefQueryDTO 岗位定义参数
     * @return ResultInfo
     */
    @Operation(summary = "根据条件查询岗位定义")
    @GetMapping("/getInfoList")
    public ResultInfo<List<PostDefVO>> getPostDefList(
            @Validated PostDefDTO.QueryDTO postDefQueryDTO) {
        return postDefService.queryPostDefList(postDefQueryDTO);
    }

}
